﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Controls="clr-namespace:Cyclops.MainApplication.Controls" 
             xmlns:vm="clr-namespace:Cyclops.MainApplication.ViewModel" 
             xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
             xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4" 
             xmlns:MainApplication="clr-namespace:Cyclops.MainApplication" 
             xmlns:ValueConverters="clr-namespace:Cyclops.MainApplication.ValueConverters"
             x:Class="Cyclops.MainApplication.ConferenceView" 
             IsVisibleChanged="UserControlIsVisibleChanged"
             d:DesignHeight="800" d:DesignWidth="500" 
             TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="ClearType"
             mc:Ignorable="d" x:Name="mainControl"
             d:DataContext="{d:DesignInstance {x:Type vm:ConferenceViewModelDesignTime}, IsDesignTimeCreatable=True}">
    <UserControl.InputBindings>
        <KeyBinding Modifiers="Control+Shift"
                        Key="V"
                        Command="{Binding ConferenceViewModel.PasteAndSend}" />
        <KeyBinding Modifiers="Control"
                        Key="S"
                        Command="{Binding ConferenceViewModel.InsertSmiles}" />
    </UserControl.InputBindings>
	<UserControl.Resources>
        
        <ValueConverters:StatusTypeToIntegerConverter x:Key="statusTypeConverter"/>
        <ValueConverters:SubjectConverter x:Key="subjectConverter"/>
        <ValueConverters:SumConverter x:Key="sumConverter" />
        <ValueConverters:RoleAndAffilationToImageConverter x:Key="roleAndAffilationConverter"/>
        <ValueConverters:BraceConverter x:Key="braceConverter" />

        <Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
            </Style.Resources>
        </Style>

        <DataTemplate x:Key="MemberInfoTemplate">
            <Border Height="32" Background="White" x:Name="rootGrid"
                    MainApplication:ContextMenuServiceExtensions.DataContext="{Binding Path=ConferenceViewModel, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                      ContextMenu="{StaticResource memberMenu}"
                    ToolTip="{Binding ClientInfo, TargetNullValue=Loading}">
                <Grid>
				    <Grid.ColumnDefinitions>
					    <ColumnDefinition Width="40" />
					    <ColumnDefinition />
				    </Grid.ColumnDefinitions>
				    <Grid.RowDefinitions>
					    <RowDefinition />
					    <RowDefinition />
				    </Grid.RowDefinitions>
				    <Border Height="27" Grid.RowSpan="2" Width="29">
					    <Border.Effect>
						    <DropShadowEffect ShadowDepth="0" BlurRadius="4" Color="#FF646464"/>
					    </Border.Effect>
					    <Image Source="{Binding AvatarUrl}" 
						       Stretch="UniformToFill" RenderOptions.BitmapScalingMode="HighQuality" />
				    </Border>

                    <StackPanel x:Name="nickPanel" HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="1" Width="{Binding Path=ActualWidth, Converter={StaticResource sumConverter}, ConverterParameter=20, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}">
                        <Image Margin="-17,-2,0,0"  Source="{Binding Role, Converter={StaticResource roleAndAffilationConverter}}" />
                        <TextBlock x:Name="nickTextBlock"  Text="{Binding Nick, FallbackValue=Nick}" FontWeight="Bold" FontSize="13.333" 
                               TextTrimming="CharacterEllipsis" Foreground="#FF565656" Margin="2,0,0,0"/>
                    </StackPanel>

                    <TextBlock Width="{Binding ActualWidth, ElementName=nickPanel}" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="1" TextTrimming="CharacterEllipsis" 
                               Text="{Binding StatusText, FallbackValue=Some_status}" Foreground="#FF919191" Margin="0,0,0,0" />
                    
			
				    <Border x:Name="awayMark" Visibility="Hidden" Grid.RowSpan="1" BorderBrush="#FF9B9B9B" BorderThickness="1" Background="White" RenderTransformOrigin="0.5,0.5" Margin="15.989,-1.737,0.759,3.177" Grid.Row="1" d:LayoutOverrides="VerticalAlignment" CornerRadius="2">
					    <Border.RenderTransform>
						    <TransformGroup>
							    <ScaleTransform/>
							    <SkewTransform AngleX="-18"/>
							    <RotateTransform Angle="-17.859"/>
							    <TranslateTransform X="-1"/>
						    </TransformGroup>
					    </Border.RenderTransform>
				    </Border>
			
				    <Border x:Name="naMark" Visibility="Hidden" Grid.RowSpan="1" BorderBrush="#FF9B9B9B" BorderThickness="1" Background="White" RenderTransformOrigin="0.5,0.5" Margin="15.989,-1.737,0.759,3.177" Grid.Row="1" d:LayoutOverrides="VerticalAlignment" CornerRadius="2">
					    <Border.RenderTransform>
						    <TransformGroup>
							    <ScaleTransform/>
							    <SkewTransform AngleX="-18"/>
							    <RotateTransform Angle="-17.859"/>
							    <TranslateTransform X="-1"/>
						    </TransformGroup>
					    </Border.RenderTransform>
					    <TextBlock Text="NA" FontWeight="Bold" Margin="2,-1,0,0" Foreground="#FFBC2E2E" FontSize="10.667"/>
				    </Border>                
			    </Grid>
        		     	
			</Border>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsModer}" Value="True">
                    <Setter TargetName="nickTextBlock" Property="Foreground" Value="Green" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Role}" Value="Devoiced">
                    <Setter TargetName="nickTextBlock" Property="Foreground" Value="#9D9D9D" />
                </DataTrigger>
                <DataTrigger Binding="{Binding StatusType}" Value="xa">
                    <Setter TargetName="naMark" Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding StatusType}" Value="dnd">
                    <Setter TargetName="awayMark" Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding StatusType}" Value="away">
                    <Setter TargetName="awayMark" Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="True">
                    <Setter TargetName="rootGrid" Property="Background" Value="#E3E3FD"/>
                </DataTrigger>
            </DataTemplate.Triggers>
		</DataTemplate>

        <CollectionViewSource x:Key="membersSource" Source="{Binding ConferenceViewModel.Conference.Members}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="Role" Direction="Descending"/>
                <ComponentModel:SortDescription PropertyName="Nick"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

	</UserControl.Resources>
	<Grid>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="3*" MinWidth="100" />
			<ColumnDefinition Width="180" MinWidth="100" />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition />
			<RowDefinition Height="65" />
		</Grid.RowDefinitions>

		<TextBox Height="24" IsReadOnly="True" Background="Transparent" BorderThickness="0,0,0,1" BorderBrush="#FFE5E5E5"                  
                 Text="{Binding ConferenceViewModel.Conference.Subject, Mode=OneWay, Converter={StaticResource subjectConverter}}" VerticalAlignment="Center" Margin="0,0,24,0"
                 TextWrapping="NoWrap" ToolTip="{Binding ConferenceViewModel.Conference.Subject, Mode=OneWay}"/>
        
        <Button Style="{StaticResource borderlessButtonStyle}" Cursor="Hand" x:Name="changeSubject" 
                Command="{Binding ConferenceViewModel.ChangeSubject}"
                HorizontalAlignment="Right"
                ToolTip="{Binding Conference.EditSubjectTooltip, Source={StaticResource ResourceWrapper}}">
            <Image Source="..\Resources\editicon.png" Width="20" Height="20"/>
        </Button>

        <Controls:ChatFlowDocumentScrollViewer UseLayoutRounding="True" Style="{DynamicResource chatFlowDocumentScrollViewerStyle}" Grid.Row="1" BorderThickness="1">
            <Controls:ChatFlowDocument x:Name="chatFlowDocument"
                                        Messages="{Binding ConferenceViewModel.Messages}" LineHeight="1" 
                                        Style="{DynamicResource flowDocumentStyle}" ContextMenu="{StaticResource chatFlowDocumentMenu}">
            </Controls:ChatFlowDocument>
		</Controls:ChatFlowDocumentScrollViewer>

        <Grid Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" >
            <Grid.RowDefinitions>
                <RowDefinition Height="23" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Button Style="{StaticResource borderlessButtonStyle}"
                    Background="White"  Margin="2,0,0,0" 
                    Command="{Binding ConferenceViewModel.NickAndStatusChange}" 
                    Content="{Binding ConferenceViewModel.NewNick, FallbackValue=Nick}"
                    HorizontalAlignment="Stretch"
                    Cursor="Hand" BorderThickness="0"/>
                      
            <ListBox Grid.Row="1"
                 x:Name="listBox"
                 BorderThickness="0"
                 ItemsSource="{Binding Source={StaticResource membersSource}}" 
                 ItemTemplate="{StaticResource MemberInfoTemplate}" ScrollViewer.CanContentScroll="False" 
                 ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                 SelectedItem="{Binding ConferenceViewModel.SelectedMember, Mode=TwoWay}"
                 ItemContainerStyle="{StaticResource ListBoxItemStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding ConferenceViewModel.StartPrivateWithSelectedMember}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ListBox>
        </Grid>
		<Grid Grid.Row="2" Grid.ColumnSpan="2">
			<Grid.ColumnDefinitions>
				<ColumnDefinition  />
				<ColumnDefinition Width="70" />
			</Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="28"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Controls:InputBox x:Name="inputBox" Grid.Row="1" FontSize="14" TextBlock.LineHeight="15" 
                                TextBlock.LineStackingStrategy="BlockLineHeight"
                                Text="{Binding ConferenceViewModel.CurrentlyTypedMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                SendCommand="{Binding ConferenceViewModel.SendMessage}"
                                ContextMenu="{StaticResource inputMenu}"/>
            <Button Grid.Row="1" Grid.Column="1" Content="{Binding Conference.Send, Source={StaticResource ResourceWrapper}}" Command="{Binding ConferenceViewModel.SendMessage}" />


            <Controls:ToolBarEx Grid.ColumnSpan="2" ToolBarTray.IsLocked="True" RenderOptions.BitmapScalingMode="NearestNeighbor" BorderThickness="0" BorderBrush="#FF5E5E5E" Margin="0,0,-11,0">
            	<Controls:ToolBarEx.Background>
            		<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
            			<GradientStop Color="White" Offset="0.462"/>
            			<GradientStop Color="White" Offset="0.747"/>
            			<GradientStop Color="#FFFBFBFB" Offset="1"/>
            			<GradientStop Color="#FEEBEBEB"/>
            		</LinearGradientBrush>
            	</Controls:ToolBarEx.Background>
                <Button Cursor="Hand" Margin="0,0,0,-4" x:Name="smilesButton" HorizontalAlignment="Left" Command="{Binding ConferenceViewModel.InsertSmiles}"
                        ToolTip="{Binding Path=Conference.SmilesTip, Source={StaticResource ResourceWrapper}}">
                    <Image Height="20" Width="20" Source="..\Resources\Smile.gif"/>
                </Button>
                <Button Cursor="Hand" Margin="10,0,0,-2" x:Name="clearButton" HorizontalAlignment="Right" Command="{Binding ConferenceViewModel.ClearOutputArea}"
                        ToolTip="{Binding Path=Conference.ClearTip, Source={StaticResource ResourceWrapper}}">
                    <Image  Height="20" Width="20" Source="..\Resources\note_delete.ico"/>
                </Button>
                <Button Cursor="Hand" Margin="10,0,0,-2" x:Name="configButton" HorizontalAlignment="Right" Command="{Binding ConferenceViewModel.ShowSettings}"
                        ToolTip="{Binding Path=Conference.SettingsTip, Source={StaticResource ResourceWrapper}}">
                    <Image Height="20" Width="20" Source="..\Resources\tools.png"/>
                </Button>
                <ToggleButton Margin="10,0,0,-2" IsChecked="{Binding Source={x:Static MainApplication:ApplicationContext.Current}, Path=DisableAllSounds}"
                        ToolTip="{Binding Path=Conference.DisableSoundsTip, Source={StaticResource ResourceWrapper}}">
                    <Image  Height="20" Width="20" Source="..\Resources\noSound.png"/>
                </ToggleButton>
            </Controls:ToolBarEx>
            
        </Grid>

		<GridSplitter Grid.RowSpan="2" Grid.Column="1" Height="Auto" Width="2" HorizontalAlignment="Left" />
        <Controls:AnimatedImage Grid.Row="1" Height="4" HorizontalAlignment="Left" Margin="-204,3,0,0" x:Name="animatedImage1" Stretch="Fill" VerticalAlignment="Top" Width="1" />
    </Grid>
</UserControl>